var rat = createFEBonesCartoon("JerryRatCanvas", 960, 150, 900, 140, 10);
var drag = {
	down: false,
	pressed: false,
	isdrag: false,
	x: 0,
	y: 0
};

function downJerryRatCanvas(event) {
	var ex = event.offsetX * 1.5,
		ey = event.offsetY * 1.5;
	var rx = rat.getRootPosition().x,
		ry = rat.getRootPosition().y;
	if (ex > rx - 40 && ex < rx + 40 && ey > ry - 120 && ey < ry) {
		drag.x = ex - rx;
		drag.y = ey - ry;
		drag.pressed = true;
	} else {
		drag.down = true;
	}
}

function upJerryRatCanvas(event) {
	var ex = event.offsetX * 1.5,
		ey = event.offsetY * 1.5;
	var rx = rat.getRootPosition().x,
		ry = rat.getRootPosition().y;
	if (drag.pressed) {
		if (!drag.isdrag) {
			if (ex > rx - 40 && ex < rx + 40 && ey > ry - 120 && ey < ry) {
				rat.qure();
			}
		} else {
			drag.isdrag = false;
			var rx = rat.getRootPosition().x,
				ry = rat.getRootPosition().y;
			rat.moveRoot(0, 140 - ry, Math.abs(140 - ry));
		}
		drag.pressed = false;
	} else if (drag.down) {
		if (ex < rx) {
			rat.walk(rx - ex);
		} else {
			rat.walk(rx + 110);
		}
		drag.down = false;
	}
}

function moveJerryRatCanvas(event) {
	if (!drag.isdrag && drag.pressed) {
		drag.isdrag = true;
	}
	if (drag.isdrag) {
		var ex = event.offsetX * 1.5,
			ey = event.offsetY * 1.5;
		var rx = ex - drag.x,
			ry = ey - drag.y;
		rat.setRootPosition(rx, ry);
	}
}
